var baseUrl="http://"+window.location.hostname;

if (window.location.hostname==='localhost'){
  baseUrl="https://v6.asrj.net";
  // baseUrl="https://t6.asrj.net";
// baseUrl = "http://192.168.1.211";
// baseUrl = "http://192.168.1.211:9551";
}
function ajax(type, url, data, successFunction, errorFunction,authorization) {
  $.ajax({
    url: baseUrl+url,
    data: type==='get'?data:JSON.stringify(data),
    //请求类型
    type: type,
    //响应体结果
    dataType: 'json',
    //成功的回调
    success: successFunction,
    //失败的回调
    error: errorFunction,
    //超时时间
    timeout: 30000,
    //头信息
    headers: {
      'accept':'application/json',
      'Content-Type': 'application/json',
      // "content-type":"application/x-www-form-urlencoded",
      'Authorization':'Bearer '+authorization,
    }
  });
}

function redirect(page,data){
  let url=baseUrl+'/wx'+page;
  if (data){
    url=url+'?';
    for (let key in data){
      url=url+key+'='+data[key]+'&';
    }
    url=url.substring(0,url.length-1);
  }
  location.href = url;
}


function getUrlCode() {
  // 截取url中的code方法
  let url = location.search;
  let theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  return theRequest;
}
